package com.itheima;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("张三");
        list.add("张三");
        list.add("张三");
        list.add("张三");
        System.out.println(list);

        ArrayList<String> newList = new ArrayList<>((new HashSet<>()));
        System.out.println(newList);
        //1.创建HashSet对象
        HashSet<String> hashSet = new HashSet<>();
        //2.保存数据
        hashSet.add("张三");
        hashSet.add("李四");
        hashSet.add("王五");
        hashSet.add("赵六");
        hashSet.add("钱七");
        System.out.println(hashSet);
        //3.取数据（迭代器）
        Iterator<String> iterator = hashSet.iterator();
        while(iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
        for (int i = 0; i < hashSet.size(); i++){

        }//用不了



    }
}